From d7fae1403012fbebd4f0399a8748312fa4d67143 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 30 Jan 2025 11:55:19 +0100 Subject: [PATCH] gpsd: add hotplug handling The 'gpsd' offers the possibility to call the script '/etc/gpsd/device-hook' when a GPS source was added or removed via gpsdctl. In addition to the '/etc/gpsd/device-hook' call an event is now triggered too after the 'gpsd' has started. This allows scripts to configurre 'gpsd' receivers. The following events are available for '/etc/hotplug.d/gpsd' scripts: * ACTIVATE via '/etc/gpsd/device-hook' * DEACTIVATE via '/etc/gpsd/device-hook' * STARTED via '/etc/init.d/gpsd' Signed-off-by: Florian Eckert --- utils/gpsd/Makefile | 5 ++++- utils/gpsd/files/etc/gpsd/device-hook | 19 +++++++++++++++++++ utils/gpsd/files/etc/hotplug.d/gpsd/00-debug | 14 ++++++++++++++ utils/gpsd/files/gpsd.init | 9 +++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 utils/gpsd/files/etc/gpsd/device-hook create mode 100644 utils/gpsd/files/etc/hotplug.d/gpsd/00-debug diff --git a/utils/gpsd/Makefile b/utils/gpsd/Makefile index 5b52dcfb38..ac568fbc2b 100644 --- a/utils/gpsd/Makefile +++ b/utils/gpsd/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gpsd PKG_VERSION:=3.25 -PKG_RELEASE:=3 +PKG_RELEASE:=4 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=@SAVANNAH/$(PKG_NAME) @@ -141,6 +141,9 @@ define Package/gpsd/install $(INSTALL_BIN) ./files/gpsd.init $(1)/etc/init.d/gpsd $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/gpsd $(1)/usr/sbin/ + + $(INSTALL_DIR) $(1)/etc/gpsd + $(INSTALL_BIN) ./files/etc/gpsd/device-hook $(1)/etc/gpsd/ endef define Package/gpsd-clients/install diff --git a/utils/gpsd/files/etc/gpsd/device-hook b/utils/gpsd/files/etc/gpsd/device-hook new file mode 100644 index 0000000000..42f986c8fb --- /dev/null +++ b/utils/gpsd/files/etc/gpsd/device-hook @@ -0,0 +1,19 @@ +#!/bin/sh + +main() { + local device="$1" + local action="$2" + + case "$action" in + "ACTIVATE") + env -i ACTION="$action" DEVICE="$device" \ + /sbin/hotplug-call gpsd + ;; + "DEACTIVATE") + env -i ACTION="$action" DEVICE="$device" \ + /sbin/hotplug-call gpsd + ;; + esac +} + +main "$@" diff --git a/utils/gpsd/files/etc/hotplug.d/gpsd/00-debug b/utils/gpsd/files/etc/hotplug.d/gpsd/00-debug new file mode 100644 index 0000000000..ca55fcdedb --- /dev/null +++ b/utils/gpsd/files/etc/hotplug.d/gpsd/00-debug @@ -0,0 +1,14 @@ +#!/bin/sh + +gps_log() { + local level="$1"; shift + + [ "$level" = "debug" ] && return + logger -p "daemon.${level}" -t "gpsd(debug)[$$]" "hotplug: $*" +} + +main() { + gps_log info "$(env)" +} + +main "$@" diff --git a/utils/gpsd/files/gpsd.init b/utils/gpsd/files/gpsd.init index ba5563e858..ee1fabf69b 100644 --- a/utils/gpsd/files/gpsd.init +++ b/utils/gpsd/files/gpsd.init @@ -49,3 +49,12 @@ service_triggers() { procd_add_reload_trigger "$NAME" procd_add_validation validate_section_gpsd } + +service_started() { + local enabled + + enabled="$(uci_get gpsd core enabled 0)" + [ "$enabled" = "0" ] && return + + env -i ACTION="STARTED" /sbin/hotplug-call gpsd +} -- 2.30.2